-- PropStatM
-- create by zouyb
-- 存储prop用到的统计数据

module("PropStatM", package.seeall);

-- 所有子规则
local rules = {};

-- 奖励信息
local bonusInfo = nil;

-- 初始
local _init = false;
function init()
    -- 载入所有的规则处理子模块
	if not _init then 
    	rules = LOAD_PATH("game/logic/module/prop_stat");
		_init = true;
	end
	
    -- 关注玩家离开地牢的事件
    EventMgr.removeAll("PropStatM");
    EventMgr.register("PropStatM", event.LEAVE_DUNGEON, function()
        clear();
    end);    
end

-- 清空统计信息
function clear()
    ME.user.dbase:set("prop_stat", {});
end

-- 设置data1
function setData1(user, propRule, value)
    local propId = PropM.getPropId(propRule);

	local stat = user.dbase:query("prop_stat");
	if stat == nil then
		stat = {};
	end	
		
    if stat[propId] == nil then
        stat[propId] = {};
	end	
		
    stat[propId][1] = value;
	user.dbase:set("prop_stat", stat);
end

-- 设置data2
function setData2(user, propRule, value)
    local propId = PropM.getPropId(propRule);

	local stat = user.dbase:query("prop_stat");
	if stat == nil then
		stat = {};
	end	
		
    if stat[propId] == nil then
        stat[propId] = {};
	end	
		
    stat[propId][2] = value;
	user.dbase:set("prop_stat", stat);
end

-- 获取data1
function getData1(user, propRule)
	local propId = PropM.getPropId(propRule);

	local stat = user.dbase:query("prop_stat");
	if stat == nil then
		return 0;
	end	
		
    if stat[propId] == nil then
		return 0;
	end	
	
    return stat[propId][1] or 0;
end

-- 获取data2
function getData2(user, propRule)
	local propId = PropM.getPropId(propRule);

	local stat = user.dbase:query("prop_stat");
	if stat == nil then
		return 0;
	end	
		
    if stat[propId] == nil then
		return 0;
	end	
	
    return stat[propId][2] or 0;
end





